from PySide2.QtGui import QPixmap
from boot import (Union, QWidget, Qt, SaleCurrentFilter, CurrentSelectedID, logger, GlobalWidget, IMG_ROOT_DIR,
                  QHBoxLayout, PushButton, QApplication, PDF_ROOT_DIR, os, QLineEdit)
from view.widget.qq9_page_base import QQ9PageBase
from view.pages.utils.message_box import message_box
from view.com.sale_content_frame import SaleContentFrame
from view.com.sale_list_frame import SaleListFrame
from view.pages.utils.map import sale_content_dict_map
from view.pages.utils.db_d import db_cust_wrapper, db_cust_and_sale_wrapper
from db.db_customer import DBCustomer
from db.db_sale import DBSale
from view.widget.qq9_messagebox import QQ9MessageBox, QQ9MessageBoxWidget, QQ9TipsMessageWidget
from view.widget.qq9_label import QQ9FromTitle
from view.widget.qq9_combobox import QQ9ComboBox
from view.widget.qq9_date_picker import QQ9DatePicker
from utils.id import generate_id
from view.widget.qq9_tabel_widget import QQ9EditTabelWidget
from view.widget.qq9_general_wrapper import popup
import json
from pynput.keyboard import Controller
from utils.save_excel import SaveExcel
from utils.file import copy_file, copy_file_rename, clear_directory
from view.widget.qq9_line_edit import QQ9LineEdit
from utils.pdf import excel_to_pdf
import hashlib


__all__ = ["PageSales"]


SHOW_BACK_NAME: bool = True
FILTER_ADD_NAME: str = ""
FILTER_ADD_DATETIME: str = ""
CREATE_PDF_LOCK = False

DELETE_RESULT: str = ""


# TODO 待开发
class PageSales(QQ9PageBase):

    @db_cust_wrapper
    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 cust_db: DBCustomer = None
                 ):
        super().__init__(parent)

        # 初始化筛选的姓名（以创建的第一个名字为准）
        try:
            SaleCurrentFilter.cust_id = cust_db.get_all_info()[0]["cust_id"]
        except IndexError as ie:
            logger.warning(f"{ie}初始化SaleCurrentFilter.cust_id错误，可能当前没有用户存在")

        # 创建销货清单列表
        self.sale_list_frame = SaleListFrame()
        self.main_h_layout.addWidget(self.sale_list_frame)

        # 创建销货清单内容框架
        self.sale_content_frame = SaleContentFrame()
        self.main_h_layout.addWidget(self.sale_content_frame)

        # 初始化步骤
        # 1.刷新列表内容
        self.show_list_widget()
        # 2.绑定list_widget的点击事件(选择改变)
        self.sale_list_frame.list_widget.itemSelectionChanged.connect(self.show_content_widget)
        # 3.编辑信号
        self.sale_list_frame.search_list_frame.edit_button.sgn_clicked.connect(self.set_sale_info)
        # 4.删除信号
        self.sale_list_frame.search_list_frame.delete_button.sgn_clicked.connect(self.delete_sale_info)
        # 5.绑定新建按钮信号
        self.sale_list_frame.search_list_frame.add_button.sgn_clicked.connect(self.filter_add_sale_info)
        # 6绑定筛选按钮信号
        self.sale_list_frame.search_list_frame.filter_button.sgn_clicked.connect(self.filter_sale_info)
        # 8.绑定截屏按钮信号
        self.sale_list_frame.search_list_frame.pdf_button.sgn_clicked.connect(self.save_to_pdf)

    @sale_content_dict_map
    def show_list_widget(self, new_dict_list= None):
        # 1.刷新列表
        self.sale_list_frame.list_widget.refresh_list_widget(new_dict_list, show_back_name=SHOW_BACK_NAME)
        # 2.切换成LOGO
        self.sale_content_frame.set_no_content()

    @sale_content_dict_map
    def edit_list_widget(self, new_dict_list=None):
        # 编辑之后刷新列表
        self.sale_list_frame.list_widget.edit_list_widget(new_dict_list, show_back_name=SHOW_BACK_NAME)

    @sale_content_dict_map
    def delete_list_widget(self, new_dict_list=None):
        # 删除之后刷新列表
        self.sale_list_frame.list_widget.delete_list_widget(new_dict_list, show_back_name=SHOW_BACK_NAME)

    @sale_content_dict_map
    def add_list_widget(self, new_dict_list=None):
        # 添加之后刷新列表
        self.sale_list_frame.list_widget.add_list_widget(new_dict_list, show_back_name=SHOW_BACK_NAME)

    @db_cust_and_sale_wrapper
    def show_content_widget(self, cust_db: DBCustomer, sale_db: DBSale):
        # 刷新内容
        try:
            # 1.获取选中的Sale信息
            sale_info_dict = sale_db.get_info(CurrentSelectedID.sale_selected_id)
            # 2.获取cust信息
            cust_info_dict = cust_db.get_info(sale_info_dict["cust_id"])
            # 3.设置内容信息
            # 3.1 时间显示格式更改
            date_list = sale_info_dict["sale_datetime"].split("/")
            self.sale_content_frame.set_info(
                sale_id=sale_info_dict["sale_id"],
                cust_name=cust_info_dict["cust_name"],
                sale_datetime=date_list[0] + "年" + date_list[1] + "月" + date_list[2] + "日",
                sale_list=sale_info_dict["sale_list"]
            )
            # 4.显示画面
            self.sale_content_frame.set_yes_content()
        except TypeError as te:
            self.show_list_widget()
            logger.warning(f"{te}由于删除了项目，本地获取item_id时不存在")

    @message_box(title="编辑销货清单", width=1250, height=982)
    @db_cust_and_sale_wrapper
    @popup
    def set_sale_info(self, w: QQ9MessageBox= None, cust_db: DBCustomer=None, sale_db: DBSale=None):
        GlobalWidget.root.showMaximized()
        # 编辑销货清单
        if CurrentSelectedID.sale_selected_id == "":
            return "没有选中任何销货清单", False
        try:
            c = SaleEditFrame(parent=w, add=True)
        except TypeError:
            logger.warning("没有选择用户，或用户不存在")
            # 2.切换成LOGO
            self.sale_content_frame.set_no_content()
            # 3.刷新列表
            self.delete_list_widget()
            return "没有选择用户，或用户不存在", False
        if w.exec():
            # 1.获取设置的客户ID
            try:
                cust_name = c.sale_message_box_info.cust_name_combobox.text()
                cust_id = cust_db.get_id_by_name(cust_name)
            except TypeError:
                logger.warning("没有选择用户，或用户不存在")
                return "没有选择用户，或用户不存在", False
            # 2.获取日期
            sale_datetime = c.sale_message_box_info.sale_datetime_combobox.get_date()
            # 4.获取表格中的数据
            sale_list = c.table.table.get_values()
            # 5.写入数据库
            sale_db.update_sale_info(
                cust_id=cust_id,
                sale_datetime=sale_datetime,
                sale_list=json.dumps({"content": sale_list}),
                sale_id = CurrentSelectedID.sale_selected_id,
            )
            # 7.更改当前筛选条件
            SaleCurrentFilter.cust_id = cust_id
            # 8.刷新列表
            self.add_list_widget()
            return f"{cust_name}的{sale_datetime}的清单编辑成功", True
        else:
            return "取消编辑", False

    @message_box(title="新建销货清单-条件筛选", width=400, height=250)
    @db_cust_and_sale_wrapper
    def filter_add_sale_info(self, w: QQ9MessageBox = None, cust_db: DBCustomer = None, sale_db: DBSale = None):
        GlobalWidget.root.showMaximized()
        # 筛选条件
        global FILTER_ADD_NAME, FILTER_ADD_DATETIME
        c = FilterFrame(parent=w, add=True)
        if w.exec():
            # 1.获取筛选姓名
            FILTER_ADD_NAME = c.name_combobox.text()
            # 2.获取发货日期
            FILTER_ADD_DATETIME = c.datetime_combobox.get_date()
            # 3.打开编辑窗口
            self.add_sale_info()

    @message_box(title="新建销货清单", width=1250, height=982)
    @db_cust_and_sale_wrapper
    def add_sale_info(self, w: QQ9MessageBox= None, cust_db: DBCustomer=None, sale_db: DBSale=None):
        global FILTER_ADD_NAME, FILTER_ADD_DATETIME
        c = SaleEditFrame(parent=w)
        sale_id = generate_id("10000")
        c.sale_message_box_info.sale_id_label.setText(sale_id)
        # 更新客户名称
        c.sale_message_box_info.cust_name_combobox.setText(FILTER_ADD_NAME)
        # 更新发货日期
        c.sale_message_box_info.sale_datetime_combobox.set_date(FILTER_ADD_DATETIME)
        if w.exec():
            # 1.获取设置的客户ID
            try:
                cust_name = c.sale_message_box_info.cust_name_combobox.text()
                cust_id = cust_db.get_id_by_name(cust_name)
            except TypeError:
                logger.warning("没有选择用户，或用户不存在")
                return
            # 2.获取日期
            sale_datetime = c.sale_message_box_info.sale_datetime_combobox.get_date()
            # 3.获取sale_id（已经有了）
            # 4.获取表格中的数据
            sale_list = c.table.table.get_values()
            # 5.写入数据库
            sale_db.add_info(
                sale_id=sale_id,
                cust_id=cust_id,
                sale_datetime=sale_datetime,
                sale_list=json.dumps({"content": sale_list})
            )
            # 6.更改当前选中ID
            CurrentSelectedID.sale_selected_id = sale_id
            # 7.更改当前筛选条件
            SaleCurrentFilter.cust_id = cust_id
            # 8.刷新列表
            self.add_list_widget()

    @message_box(title="删除销货清单", width=400, height=150)
    @db_cust_and_sale_wrapper
    def delete_sale_info(self, w: QQ9MessageBox= None, cust_db: DBCustomer=None, sale_db: DBSale=None):
        GlobalWidget.root.showMaximized()
        # 删除销货清单
        if CurrentSelectedID.sale_selected_id == "":
            return "没有选中任何销货清单", False
        QQ9TipsMessageWidget(parent=w, text="确定删除此销货清单吗？")
        if w.exec():
            # 1.删除客户信息密码确认
            self.delete_sale_info_configuration()

    @message_box(title="删除销货清单密码确认", width=400, height=150)
    @db_cust_and_sale_wrapper
    def delete_sale_info_configuration(self, w: QQ9MessageBox= None, cust_db: DBCustomer=None, sale_db: DBSale=None):
        # 删除客户信息密码确认
        global DELETE_RESULT
        c = PasswordEditFrame(parent=w)
        if w.exec():
            # 哈希256加密密码
            hash_object = hashlib.sha256(c.password_edit.text().encode())
            hex_dig = hash_object.hexdigest()
            if hex_dig == "c67ea1a7c60a833a8b56a9e2b99d8e4803b4d3dcb7dc5982313a51ab264ee15b":
                # 1.在数据库中删除
                sale_db.delete_info(CurrentSelectedID.sale_selected_id)
                # 2.切换成LOGO
                self.sale_content_frame.set_no_content()
                # 3.刷新列表
                self.delete_list_widget()
                # 4.复位删除ID
                CurrentSelectedID.sale_selected_id = ""
                # 4.结果提醒
                DELETE_RESULT = "删除成功"
            else:
                DELETE_RESULT = "密码错误，删除失败"
            self.delete_finish_tips()


    @message_box(title="删除结果", width=300, height=150)
    def delete_finish_tips(self, w: QQ9MessageBox=None):
        # 删除结果信息
        global DELETE_RESULT
        QQ9TipsMessageWidget(parent=w, text=DELETE_RESULT)
        if w.exec():
            pass

    @message_box(title="选择筛选按条件", width=400, height=170)
    @db_cust_and_sale_wrapper
    @popup
    def filter_sale_info(self, w: QQ9MessageBox = None, cust_db: DBCustomer = None, sale_db: DBSale = None):
        GlobalWidget.root.showMaximized()
        # 更改过滤条件
        c = FilterFrame(parent=w)
        if w.exec():
            # 1.更改筛选条件
            cust_name = c.name_combobox.text()
            if cust_name != "":
                SaleCurrentFilter.cust_id = cust_db.get_id_by_name(cust_name)
                # 2.刷新列表
                self.show_list_widget()
                # 3.切换成LOGO
                self.sale_content_frame.set_no_content()
                # 4.复位ID防止误删除或错误编辑
                CurrentSelectedID.sale_selected_id = ""
                return "筛选成功", True
            else:
                return "没有选择用户，或用户不存在", False
        else:
            return "筛选已取消", False

    @popup
    def screenshot(self):
        # 截图
        try:
            width, height = GlobalWidget.root.width(), GlobalWidget.root.height()
            GlobalWidget.root.resize(1581, 1006)
            pixmap = self.sale_content_frame.grab()
            GlobalWidget.root.resize(width, height)
            pixmap.save(IMG_ROOT_DIR + "/screenshot/" + "发货清单截图" + ".png", "PNG", quality=100)
            # 弹出文件窗口
            # os.startfile(IMG_ROOT_DIR + "/screenshot/")
            # 自动放入粘贴板
            img = QPixmap(IMG_ROOT_DIR + "/screenshot/" + "发货清单截图" + ".png")
            clipboard = QApplication.clipboard()
            clipboard.setPixmap(img)
            return "发货清单截图已经复制入粘贴板", True
        except Exception as e:
            logger.error(e)
            return "截图失败", False

    @db_cust_and_sale_wrapper
    @popup
    def save_to_pdf(self, cust_db: DBCustomer=None, sale_db: DBSale=None):
        global CREATE_PDF_LOCK
        # 锁检测
        if not CREATE_PDF_LOCK:
            # 1.上锁
            CREATE_PDF_LOCK = True

            try:
                # 1. 清空输出目录
                clear_directory(PDF_ROOT_DIR + "/tmp")

                # 2.获取数据库信息
                # 2.1获取选中的Sale信息
                sale_info_dict = sale_db.get_info(CurrentSelectedID.sale_selected_id)
                # 2.2获取cust信息
                cust_info_dict = cust_db.get_info(sale_info_dict["cust_id"])
                cust_name = cust_info_dict["cust_name"]
                # 2.3设置内容信息
                # 时间显示格式更改
                sale_datime = sale_info_dict["sale_datetime"].replace("/", "-")

                # 生成FileName
                file_name = sale_datime + cust_name + CurrentSelectedID.sale_selected_id

                # 3.复制源Excel
                copy_file_rename(
                    src_path=PDF_ROOT_DIR + "/src/root.xlsx",
                    dst_dir=PDF_ROOT_DIR + "/dst",
                    dst_filename = file_name + ".xlsx"
                )

                # 4.保存数据
                with SaveExcel(PDF_ROOT_DIR + "/dst/" + file_name + ".xlsx") as excel:
                    excel.save_excel(
                        sale_id=sale_info_dict["sale_id"],
                        cust_name=cust_info_dict["cust_name"],
                        sale_datetime=sale_datime,
                        sale_list=sale_info_dict["sale_list"]
                    )

                # 生成pdf
                excel_to_pdf(PDF_ROOT_DIR + "/dst/" + file_name + ".xlsx", PDF_ROOT_DIR + "/tmp/" + file_name + ".pdf")

                # 打开目录
                os.startfile(PDF_ROOT_DIR + "/tmp/")
                CREATE_PDF_LOCK = False
                return "PDF生成成功", True

            except Exception as e:
                logger.debug(f"PDF生成失败，可能是因为没有关闭之前打开的PDF文件，请关闭后再重新生成{e}")
                CREATE_PDF_LOCK = False
                return f"PDF生成失败，可能是因为没有关闭之前打开的PDF文件，请关闭后再重新生成", False

        else:
            return "正在生成PDF，请勿重复操作", False


class SaleEditFrame(QQ9MessageBoxWidget):

    @db_cust_and_sale_wrapper
    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 add: bool = False,
                 cust_db: DBCustomer = None,
                 sale_db: DBSale = None
                 ):
        super().__init__(parent)

        self.main_g_layout.setAlignment(Qt.AlignTop)
        self.main_g_layout.setContentsMargins(35, 10, 0, 0)
        self.main_g_layout.setSpacing(20)

        # 清单信息
        self.sale_message_box_info = SaleMessageBoxInfo()
        self.main_g_layout.addWidget(self.sale_message_box_info, 0, 0)

        # 功能按钮
        self.tool_buttons_widget = ToolButtonsWidget()
        self.main_g_layout.addWidget(self.tool_buttons_widget, 1, 0)

        # 创建销货清单表
        self.table = QQ9EditTabelWidget()
        self.main_g_layout.addWidget(self.table, 2, 0)

        if add:
            # 获取销货清单信息
            sale_data = sale_db.get_info(CurrentSelectedID.sale_selected_id)
            # 1.获取表格数据
            self.table.table.create_edit_table_with_content(json.loads(sale_data["sale_list"])["content"])
            # 2.获取ID
            self.sale_message_box_info.sale_id_label.setText(sale_data["sale_id"])
            # 3.获取客户姓名
            cust_id = sale_data["cust_id"]
            cust_name = cust_db.get_name_by_id(cust_id)
            self.sale_message_box_info.cust_name_combobox.setText(cust_name)
            # 4.获取发货时间
            self.sale_message_box_info.sale_datetime_combobox.set_date(sale_data["sale_datetime"])
        else:
            self.table.table.create_edit_empty_table()


class FilterFrame(QQ9MessageBoxWidget):

    @db_cust_wrapper
    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 cust_db: DBCustomer = None,
                 add: bool = False,
                 ):
        super().__init__(parent=parent)

        self.name_label = QQ9FromTitle(text="客户姓名")

        # 客户姓名
        self.name_combobox = QQ9ComboBox()
        self.name_combobox.addItems([i["cust_name"] for i in cust_db.get_all_info()])

        self.main_g_layout.addWidget(self.name_label, 0, 0)
        self.main_g_layout.addWidget(self.name_combobox, 0, 1)

        if add:
            self.datetime_label = QQ9FromTitle(text="发货时间")
            self.datetime_combobox = QQ9DatePicker()
            self.datetime_combobox.set_current_date()
            self.main_g_layout.addWidget(self.datetime_label, 1, 0)
            self.main_g_layout.addWidget(self.datetime_combobox, 1, 1)


class SaleMessageBoxInfo(QWidget):

    @db_cust_wrapper
    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 cust_db: DBCustomer = None
                 ):
        super().__init__(parent=parent)

        # 主布局
        self.main_h_layout = QHBoxLayout()
        self.main_h_layout.setContentsMargins(0, 0, 0, 0)
        self.main_h_layout.setSpacing(20)
        self.main_h_layout.setAlignment(Qt.AlignLeft)
        self.setLayout(self.main_h_layout)

        # 清单编号
        self.sale_id_title_label = QQ9FromTitle(text="清单编号")
        self.main_h_layout.addWidget(self.sale_id_title_label)
        self.sale_id_label = QQ9FromTitle(text="200000202501101203143")
        self.sale_id_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.sale_id_label.setFixedWidth(220)
        self.main_h_layout.addWidget(self.sale_id_label)

        blank= QQ9FromTitle(text="     ")
        self.main_h_layout.addWidget(blank)

        # 客户姓名
        self.cust_name_title_label = QQ9FromTitle(text="客户姓名")
        self.main_h_layout.addWidget(self.cust_name_title_label)
        self.cust_name_combobox = QQ9ComboBox()
        self.main_h_layout.addWidget(self.cust_name_combobox)
        self.cust_name_combobox.addItems([i["cust_name"] for i in cust_db.get_all_info()])

        blank= QQ9FromTitle(text="     ")
        self.main_h_layout.addWidget(blank)

        # 发货时间
        self.sale_datetime_title_label = QQ9FromTitle(text="发货时间")
        self.main_h_layout.addWidget(self.sale_datetime_title_label)
        self.sale_datetime_combobox = QQ9DatePicker()
        self.main_h_layout.addWidget(self.sale_datetime_combobox)


class ToolButtonsWidget(QWidget):

    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 ):
        super().__init__(parent=parent)

        # 主布局
        self.main_h_layout = QHBoxLayout()
        self.main_h_layout.setContentsMargins(0, 0, 0, 0)
        self.main_h_layout.setSpacing(20)
        self.main_h_layout.setAlignment(Qt.AlignLeft)
        self.setLayout(self.main_h_layout)

        button_1 = PushButton(text = "×")
        button_1.setFocusPolicy(Qt.NoFocus)
        button_1.clicked.connect(lambda : self.on_key_pressed("×"))
        self.main_h_layout.addWidget(button_1)

        button_2 = PushButton(text = "mm²")
        button_2.setFocusPolicy(Qt.NoFocus)
        button_2.clicked.connect(lambda : self.on_key_pressed("²"))
        self.main_h_layout.addWidget(button_2)

        button_3 = PushButton(text = "BV")
        button_3.setFocusPolicy(Qt.NoFocus)
        button_3.clicked.connect(lambda : self.on_key_pressed("BV"))
        self.main_h_layout.addWidget(button_3)

        button_4 = PushButton(text = "BVR")
        button_4.setFocusPolicy(Qt.NoFocus)
        button_4.clicked.connect(lambda : self.on_key_pressed("BVR"))
        self.main_h_layout.addWidget(button_4)

        button_5 = PushButton(text = "BLVVB")
        button_5.setFocusPolicy(Qt.NoFocus)
        button_5.clicked.connect(lambda : self.on_key_pressed("BLVVB"))
        self.main_h_layout.addWidget(button_5)

        button_6 = PushButton(text = "BVVB")
        button_6.setFocusPolicy(Qt.NoFocus)
        button_6.clicked.connect(lambda : self.on_key_pressed("BVVB"))
        self.main_h_layout.addWidget(button_6)

        button_7 = PushButton(text = "BLV")
        button_7.setFocusPolicy(Qt.NoFocus)
        button_7.clicked.connect(lambda : self.on_key_pressed("BLV"))
        self.main_h_layout.addWidget(button_7)

        button_8 = PushButton(text = "BLXY")
        button_8.setFocusPolicy(Qt.NoFocus)
        button_8.clicked.connect(lambda : self.on_key_pressed("BLXY"))
        self.main_h_layout.addWidget(button_8)

        button_9 = PushButton(text = "RVV")
        button_9.setFocusPolicy(Qt.NoFocus)
        button_9.clicked.connect(lambda : self.on_key_pressed("RVV"))
        self.main_h_layout.addWidget(button_9)

        button_10 = PushButton(text = "RVVB")
        button_10.setFocusPolicy(Qt.NoFocus)
        button_10.clicked.connect(lambda : self.on_key_pressed("RVVB"))
        self.main_h_layout.addWidget(button_10)

        button_11 = PushButton(text = "RVS")
        button_11.setFocusPolicy(Qt.NoFocus)
        button_11.clicked.connect(lambda : self.on_key_pressed("RVS"))
        self.main_h_layout.addWidget(button_11)

        button_12 = PushButton(text = "YZ")
        button_12.setFocusPolicy(Qt.NoFocus)
        button_12.clicked.connect(lambda : self.on_key_pressed("YZ"))
        self.main_h_layout.addWidget(button_12)

        button_13 = PushButton(text = "YC")
        button_13.setFocusPolicy(Qt.NoFocus)
        button_13.clicked.connect(lambda : self.on_key_pressed("YC"))
        self.main_h_layout.addWidget(button_13)

        button_14 = PushButton(text = "(")
        button_14.setFocusPolicy(Qt.NoFocus)
        button_14.clicked.connect(lambda: self.on_key_pressed("("))
        self.main_h_layout.addWidget(button_14)

        button_15 = PushButton(text = ")")
        button_15.setFocusPolicy(Qt.NoFocus)
        button_15.clicked.connect(lambda: self.on_key_pressed(")"))
        self.main_h_layout.addWidget(button_15)

        button_16 = PushButton(text = "D")
        button_16.setFocusPolicy(Qt.NoFocus)
        button_16.clicked.connect(lambda: self.on_key_pressed("D"))
        self.main_h_layout.addWidget(button_16)

    @staticmethod
    def on_key_pressed(text):
        # 发送
        try:
            keyboard = Controller()
            if text == "²":
                keyboard.type("MM²")
            elif text == "×": keyboard.type("×")
            elif text == "BVR": keyboard.type("BVR ")
            elif text == "BLVVB":  keyboard.type("BLVVB ")
            elif text == "RVV":  keyboard.type("RVV ")
            elif text == "YZ": keyboard.type("YZ ")
            elif text == "YC": keyboard.type("YC ")
            elif text == "BV": keyboard.type("BV ")
            elif text == "BVVB": keyboard.type("BVVB ")
            elif text == "RVVB": keyboard.type("RVVB ")
            elif text == "BLXY": keyboard.type("BLXY ")
            elif text == "BLV": keyboard.type("BLV ")
            elif text == "RVS": keyboard.type("RVS ")
            elif text == "(": keyboard.type("(")
            elif text == ")": keyboard.type(")")
            elif text == "D": keyboard.type("D")

        except Exception as e:
            logger.warning(e)


class PasswordEditFrame(QQ9MessageBoxWidget):

    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 ):
        super().__init__(parent)

        # 标题
        self.name_label = QQ9FromTitle(text="删除密码")

        # 密码框
        self.password_edit = QQ9LineEdit()
        self.password_edit.setEchoMode(QLineEdit.Password)

        self.main_g_layout.addWidget(self.name_label, 0, 0)
        self.main_g_layout.addWidget(self.password_edit, 0, 1)